package com.javaeedev.junit;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SignOnServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if(username.equals("test") && password.equals("test")) {
            req.getSession().setAttribute("signon", Boolean.TRUE);
            resp.sendRedirect("/default.jsp");
        }
        else {
            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
    }

}
